﻿//dojo.require("dojox.grid.EnhancedGrid");
//dojo.require("dojo.data.ItemFileWriteStore");

/*
定义通用的列表类
*/
//定义一个iSun.common.list类
require([
				"dojox/grid/EnhancedGrid",
				"dojo/store/Memory",
				"dojo/data/ObjectStore",
                "dojo/data/ItemFileWriteStore",
				"dojo/_base/xhr",
                "dojox/grid/cells", "dojo/_base/array", "dojo/_base/lang", "dojox/grid/_CheckBoxSelector", "dojox/grid/_RadioSelector",
				"dojo/domReady!"
			], function (EnhancedGrid, Memory, ObjectStore, ItemFileWriteStore,xhr) {
			    xhr.get({
			        url: _dataJSON,
			        handleAs: "json"
			    }).then(function (data) {
			        store = new Memory({ data: data.items });
			        dataStore = new ObjectStore({ objectStore: store });

			        grid = new EnhancedGrid({
			            store: dataStore,
			            query: { id: "*" },
			            structure: [
					        // First, our view using the _CheckBoxSelector custom type
					        {
						        type: "dojox.grid._CheckBoxSelector"
					        },
                            [_cells]]
			        }, "grid");

			        // since we created this grid programmatically, call startup to render it
					grid.startup();
			    });
			});

var refresh = function () {
    newStore = new dojo.data.ItemFileReadStore(store);
    grid = dijit.byId("grid");
    grid.setStore(newStore);
}

var getSelectItems = function (_grid) {
    debugger;
    var items = _grid.selection.getSelected();
    if (items.length) {
        // Iterate through the list of selected items.
        // The current item is available in the variable
        // "selectedItem" within the following function:
        dojo.forEach(items, function (selectedItem) {
            if (selectedItem !== null) {
                // Iterate through the list of attributes of each item.
                // The current attribute is available in the variable
                // "attribute" within the following function:
                dojo.forEach(grid2.store.getAttributes(selectedItem), function (attribute) {
                    // Get the value of the current attribute:
                    var value = grid2.store.getValues(selectedItem, attribute);
                    // Now, you can do something with this attribute/value pair.
                    // Our short example shows the attribute together
                    // with the value in an alert box, but we are sure, that
                    // you'll find a more ambitious usage in your own code:
                    alert('attribute: ' + attribute + ', value: ' + value);
                }); // end forEach
            } // end if
        }); // end forEach
    } // end if

    return items;

}
